package com.whm.hrmanagement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONObject;
import com.whm.hrmanagement.domain.dto.UserSelectListDto;
import com.whm.system.mapper.SysDeptMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.whm.common.annotation.Log;
import com.whm.common.core.controller.BaseController;
import com.whm.common.core.domain.AjaxResult;
import com.whm.common.enums.BusinessType;
import com.whm.hrmanagement.domain.OaZrsglryda;
import com.whm.hrmanagement.service.IOaZrsglrydaService;
import com.whm.common.utils.poi.ExcelUtil;
import com.whm.common.core.page.TableDataInfo;

/**
 * hrmanagementController
 * 
 * @author whm
 * @date 2024-01-30
 */
@RestController
@RequestMapping("/hrmanagement/zrsglryda")
public class OaZrsglrydaController extends BaseController
{
    @Autowired
    private IOaZrsglrydaService oaZrsglrydaService;

    /**
     * 查询hrmanagement列表
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:zrsglryda:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaZrsglryda oaZrsglryda)
    {
//        startPage();
        List<OaZrsglryda> list = oaZrsglrydaService.selectOaZrsglrydaList(oaZrsglryda);
        return getDataTable(list);
    }

    /**
     * 导出hrmanagement列表
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:zrsglryda:export')")
    @Log(title = "hrmanagement", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaZrsglryda oaZrsglryda)
    {
        List<OaZrsglryda> list = oaZrsglrydaService.selectOaZrsglrydaList2(oaZrsglryda);
        ExcelUtil<OaZrsglryda> util = new ExcelUtil<OaZrsglryda>(OaZrsglryda.class);
        util.exportExcel(response, list, "hrmanagement数据");
    }

    /**
     * 获取hrmanagement详细信息
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:zrsglryda:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(oaZrsglrydaService.selectOaZrsglrydaById(id));
    }

    /**
     * 新增hrmanagement
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:zrsglryda:add')")
    @Log(title = "hrmanagement", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JSONObject data)
    {

        String jsonString = JSONObject.toJSONString(data.getJSONObject("form"));
        OaZrsglryda oaZrsglryda = JSONObject.parseObject(jsonString, OaZrsglryda.class);

        if (!oaZrsglrydaService.checkNickNameUnique(oaZrsglryda))
        {
            return error("新增用户档案'" + oaZrsglryda.getXingMing() + "'失败，用户档案已经已存在");
        }

        return toAjax(oaZrsglrydaService.insertOaZrsglryda(data));
    }

    /**
     * 修改hrmanagement
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:zrsglryda:edit')")
    @Log(title = "hrmanagement", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit( @RequestBody JSONObject data)
    {

        return toAjax(oaZrsglrydaService.updateOaZrsglryda(data));
    }

    /**
     * 删除hrmanagement
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:zrsglryda:remove')")
    @Log(title = "hrmanagement", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(oaZrsglrydaService.deleteOaZrsglrydaByIds(ids));
    }
    /**
     * 获取用户Select
     */

    @GetMapping("/getUserSelect")
    public AjaxResult getUserSelect()
    {

        List<UserSelectListDto> list = oaZrsglrydaService.getUserSelect();
        return success(list);
    }

}
